package com.dhsc.service.impl.ywjk.jzcl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.jkzx.ywjk.jzcl.YcmxlsVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.ywjk.jzcl.IYclxwhDao;
import com.dhsc.service.ywjk.jzcl.IYclxwhService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: YclxwhServiceImpl
 * @Description: 异常类型维护
 * @date: 2023/9/1 14:10
 * @author: gx
 */
@Service
@Slf4j
public class YclxwhServiceImpl implements IYclxwhService {

    @Autowired
    private IYclxwhDao yclxwhDao;

    @Override
    public LayuiTableVo queryYclxwh(YcmxlsVo ycmxlsVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try{
            PageMethod.startPage(ycmxlsVo.getPage(), ycmxlsVo.getLimit());
            List<YcmxlsVo> list = yclxwhDao.queryYclxwh(ycmxlsVo);
            PageInfo<YcmxlsVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch(Exception e){
            log.error("查询异常类型维护信息出错", e);
            throw new MyException("查询异常类型维护信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryQsTxtdm(YcmxlsVo ycmxlsVo) {
        ResponseObject obj = new ResponseObject();
        try{
            List<YcmxlsVo> list = yclxwhDao.queryQsTxtdm(ycmxlsVo);
            obj.setData(list);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("查询字典信息出错", e);
            throw new MyException("查询字典信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject saveYclxwh(YcmxlsVo ycmxlsVo) {
        ResponseObject obj = new ResponseObject();
        try{
            if (ycmxlsVo.getBh() == 0){
                yclxwhDao.insertYclxwh(ycmxlsVo);
            }else{
                yclxwhDao.updateYclxwh(ycmxlsVo);
            }
            obj.setStatus(200);
        }catch(Exception e){
            log.error("保存异常类型维护出错", e);
            throw new MyException("保存异常类型维护出错",e);
        }
        return obj;
    }
}
